# -*- coding: utf-8 -*-

from django.db import models
from core.models import CoreModel, table_prefix

"""执行节点对象"""


class Node(CoreModel):
    TYPE_CHOICES = (
        (0, "密码验证"),
        (1, "私钥验证"),
    )
    name = models.CharField(
        max_length=128,
        verbose_name="节点名称"
    )
    number = models.CharField(
        null=True,
        blank=True,
        max_length=128,
        verbose_name="节点型号"
    )
    address = models.CharField(
        unique=True,
        max_length=32,
        verbose_name="节点地址"
    )
    port = models.IntegerField(
        default=22,
        verbose_name="端口号"
    )
    username = models.CharField(
        null=True,
        blank=True,
        max_length=128,
        verbose_name="用户名"
    )
    password = models.CharField(
        null=True,
        blank=True,
        max_length=128,
        verbose_name="密码"
    )
    os = models.CharField(
        max_length=200,
        verbose_name="操作系统"
    )
    enable = models.CharField(
        max_length=50,
        default='0',
        verbose_name="是否启用"
    )
    pkey = models.CharField(
        null=True,
        blank=True,
        max_length=255,
        verbose_name="私钥"
    )
    pkey_passwd = models.CharField(
        null=True,
        blank=True,
        max_length=255,
        verbose_name="私钥密码",
    )
    vtype = models.SmallIntegerField(
        default=0,
        choices=TYPE_CHOICES,
        verbose_name="验证方式"
    )

    def __str__(self) -> str:
        return '%s(%s)' % (self.name, self.address)

    class Meta:
        db_table = table_prefix + "oms_node"
        verbose_name = '节点管理'
        verbose_name_plural = verbose_name
        ordering = ('-update_time',)
